#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

int testShuffle(struct gameState *state, int playerId);

int main() {
    
    int seed = 1000;
    int numPlayer = 3;
	//printf("number of copper is %d", copper);
    
	struct gameState G;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
		   sea_hag, tribute, smithy};

	initializeGame(numPlayer, k, seed, &G);
	
	int j=0;
	for (j=0;j<numPlayer;j++) {
		printf ("Player %d: ", j);
		printf ("%d points\n");
		assert(scoreFor(j, &G) == 3);
	}
    printf ("Player 0: %d\n", scoreFor(0, &G));
	printf ("Player 1: %d\n", scoreFor(1, &G));
	
	assert(scoreFor(0, &G) == 3); // check if the number of coins is correct
	assert(scoreFor(1, &G) == 3); // check if the number of coins is correct

	
	printf ("Testing scoreFor().\n");
    printf("All tests passed!\n");
	
	//test shuffle
		// new version of deck needs to have the exact same cards as before the shuffle
		// new version of deck must not be in the same order as before
	for (j=0;j<numPlayer;j++) {
		testshuffle(&G, j)
	}
	

    return 0;
}

int testShuffle(struct gameState *state, int playerId) {
	int oldDeck[MAX_POS];
	double sameOrder = 0;
	int sameCards = 0;
	int i, j;
	//make copy of current deck
	for(i=0;i<state->deckCount[playerId]-1;i++) {
		oldDeck[i] = state->deck[playerId][i];
	}
	//call the shuffle function
	shuffle(playerId, state);
	
	//test the results for all cards present
	for (i=0;i<state->deckCount[playerId]-1;i++) {
		for (j=0;j<state->deckCount[playerId]-1;j++) {
			if (oldDeck[i] = state->deck[playerId][j] ) {
				sameCards += 1; // card is still present
				if (i == j) {sameOrder += 1;} // card is still in the same poisition
				//possible addition: check neighboring cards for shift?
			}
		}	
	}
	//print data
	printf("Player %d shuffle results:\n", playerId);
	printf("%d\% of cards still in deck after shuffle\n", sameCards / (100*state->deckCount[playerId]));
	printf("%d\% of cards in the same position after shuffle\n\n", sameOrder/ (100*state->deckCount[playerId]));
	
	//assertions
	assert (sameCards == state->deckCount[playerId]);
	assert (sameOrder != state->deckCound[playerId]);
	return 0;
}